/*
* qiudot.com Inc.
* Copyright (c) 2019 All Rights Reserved.
* create by qiudot
* date:2019-10-05
*/
package com.lora.web;

import com.acooly.core.common.web.AbstractJQueryEntityController;
import com.google.common.collect.Maps;
import com.lora.entity.Alarm;
import com.lora.service.AlarmService;
import com.lora.service.EquipmentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * lora_alarm 管理控制器
 * 
 * @author qiudot
 * Date: 2019-10-05 12:02:29
 */
@Controller
@RequestMapping(value = "/manage/lora/alarm/alarm")
public class AlarmManagerController extends AbstractJQueryEntityController<Alarm, AlarmService> {
	
	private static Map<String, String> allStatuss = Maps.newLinkedHashMap();
	static {
		allStatuss.put("1", "启用");
		allStatuss.put("0", "停用");
	}

	{
		allowMapping = "*";
	}

	@Resource
	private AlarmService alarmService;

	@Resource
	private EquipmentService equipmentService;

	@Override
	protected void referenceData(HttpServletRequest request, Map<String, Object> model) {
		List<Map<String, Object>> query = equipmentService.query(Maps.newHashMap());
		model.put("equipments", query);
		Map<String, Object> map = Maps.newHashMap();
		List<Map<String, Object>> equipments = equipmentService.query(map);
		Map<String, String> allepIds = Maps.newTreeMap();
		for(Map<String, Object> m : equipments) {
			allepIds.put(m.get("eid").toString(), m.get("ename").toString() + "-" + m.get("position").toString());
		}
		model.put("equipments", equipments);
		model.put("allStatuss", allStatuss);
		model.put("allEpIds", allepIds);
	}

	@Override
	public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
		return super.index(request, response, model);
	}

	@Override
	protected Alarm onSave(HttpServletRequest request, HttpServletResponse response, Model model, Alarm entity, boolean isCreate) throws Exception {
		return super.onSave(request, response, model, entity, isCreate);
	}
}
